"""
@property包装器、修改器、删除器

Version: 0.1
Author: yuwl
Date：2024-3-26
"""

class Person(object):

    def __init__(self, name, age):
        self._name = name
        self._age = age

    # getter方法-访问器
    @property
    def name(self):
        return self._name
    
    # setter方法-修改器
    @name.setter
    def name(self, name):
        self._name = name

    # 删除器
    @name.deleter
    def name(self):
        del self._name

    @property
    def age(self):
        return self._age
    
    @age.setter
    def age(self, age):
        self._age = age

    def play(self):
        if self._age <= 16:
            print('%s正在玩飞行棋。' % self._name)
        else:
            print('%s正在玩斗地主。' % self._name) 

if __name__ == '__main__':
    person = Person('张三', 22)
    person.play()
    person.name = '李四'
    person._age = 16
    person.play()
    # 删除属性后，会报找不到该属性的错误    
    del person.name
    # AttributeError: 'Person' object has no attribute '_name'. Did you mean: 'name'?
    print(person.name)